--
-- Author: shunguo.chen
-- Date: 2018-03-16 11:16:48
--
-- ChessHeadRender 谜棋小地图头像

local AvatarIconNode = require("app.widget.AvatarIconNode")

local ClassRef = app.mvc.createRenderClass(...)

-- data = ChessPlayer
function ClassRef.createWithData(data, node)
	local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.ChessHeadNode))
	if node == nil then
		ccui.Helper:doLayout(sprite)
	end
	sprite:init(data)
	return sprite
end
function ClassRef.create(node)
    return ClassRef.createWithData(nil, node)
end

function ClassRef:init(data)
	self.super.init(self, data)

	self._avatarIcon = AvatarIconNode.new(self._ui.Panel_head, "head")

	self:refresh()
end

function ClassRef:refresh()
	if self._data then
		self._avatarIcon:update(self._data.baseInfo)
		local isMe = self._data:isMe()
		self._ui.bg_1:setVisible(not isMe)
		self._ui.bg_2:setVisible(isMe)
	end
end

return ClassRef